/** --- 房间状态 --- */
// 空房间
export const ROOM_STATUS_EMPTY = 'EMPTY';
// 有人在房间中等待(仅1个人)
export const ROOM_STATUS_WAIT = 'WAIT';
// 多个人在房间中等待
export const ROOM_STATUS_MULTIPLE_WAIT = 'MULTIPLE_WAIT';
// 匹配成功
export const ROOM_STATUS_MATCH_SUCCESS = 'MATCH_SUCCESS';
// 对战中
export const ROOM_STATUS_BATTLE = 'BATTLE';
// 对战有一方超时了
export const ROOM_STATUS_TIMEOUT = 'TIMEOUT';
// 对战结束，等待结算
export const ROOM_STATUS_BATTLE_OVER = 'BATTLE_OVER';


/** --- 加入房间的类型 --- */
// 匹配对战
export const JOIN_ROOM_TYPE_RANDOM = 'random';
// 开房约战
export const JOIN_ROOM_TYPE_FREEDOM = 'freedom';

/**
 * 获取一个随机ID
 * @param len
 * @param radix
 * @return {string}
 */
export const getRandomId = (len, radix = 10) => {
  const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  const uuid = [];
  let i;
  radix = radix || chars.length;
  if (len) {
    // Compact form
    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
  } else {
    // rfc4122, version 4 form
    let r;
    // rfc4122 requires these characters
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4';
    // Fill in random data.  At i==19 set the high bits of clock sequence as
    // per rfc4122, sec. 4.1.5
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | Math.random() * 16;
        uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r];
      }
    }
  }
  return uuid.join('');
}
